package com.hkw.utils;

import com.hkw.model.Student;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
 * ResultSetHandler的实现类，将查询到的结果集封装成List<Student>集合
 */
public class ArrayStudentHandler implements ResultSetHandler<List<Student>> {
    List<Student>  list = new ArrayList<>();
    @Override
    public List<Student> handle(ResultSet resultSet) throws SQLException {
        while(resultSet.next()) {
            Student student = new Student();
            student.setId(resultSet.getInt("id"));
            student.setBirthday(resultSet.getDate("birth").toString());
            student.setEmail(resultSet.getString("email"));
            student.setName(resultSet.getString("name"));
            student.setClassId(resultSet.getInt("classId"));
            student.setSex(resultSet.getString("sex"));
            student.setRemark(resultSet.getString("remark"));
            list.add(student);
        }
        return list;
    }
}
